package cz.myslivec.knihovna.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import cz.myslivec.knihovna.entity.Publisher;

@Name("publisherDaoImpl")
@AutoCreate
public class PublisherDaoImpl implements PublisherDao {

	@In
	private EntityManager entityManager;

	public void create(Publisher publisher) {
		entityManager.persist(publisher);
	}

	public void delete(Publisher publisher) {
		entityManager.remove(publisher);
	}

	public void update(Publisher publisher) {
		entityManager.merge(publisher);
	}

	public Publisher getPublisher(long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<Publisher> list() {
		Query query = entityManager.createQuery("from Publisher");
		return (List<Publisher>)query.getResultList();
	}

}
